/**
 * 
 */
package map;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;

import org.json.JSONArray;

import data.Parser;

/**
 * @author Mathias
 *
 */


public class Train {
	public static enum State { ERROR, FINISHED, SLEEPING, RUNNING };
	
	public final String id;
	public final Calendar date, started, finished, nextrun;
	public final State status;
	
	LinkedList<Waypoint> stations;
	HashSet<Integer> stationsID=new HashSet<Integer>();
	
	public Train(String id, Calendar date, String status, Calendar started, Calendar finished, Calendar nextrun, JSONArray stations){
		this.id = id;
		this.date = date;
		switch (status){
		case "N":	this.status = null;
					break;
		case "E":	this.status = State.ERROR;
					break;
		case "F":	this.status = State.FINISHED;
					break;
		case "S":	this.status = State.SLEEPING;
					break;
		case "X":	this.status = State.RUNNING;
					break;
		default:	this.status = null;
		}
		
		this.started = started;
		this.finished = finished;
		this.nextrun = nextrun;
		
		this.stations = Parser.parseWaypoints(stations);
		
		for (Waypoint w: this.stations)
			stationsID.add(w.getStation());
	}
	
}
